const express = require('express');
const typeModel = require('../model/types')
const router = express.Router();

// 添加类型
router.post('/add',async (req,res)=>{
   const {name,id} = req.body;
   
   const resData =await typeModel.create({
            name:name,
            id
       })
    if(resData) {
        res.send({
            msg:'添加成功',
            code:1
        })
    } else {
        res.send({
            msg:'添加失败',
            code:0
        })
    }
   
})
// /type/all
router.get('/all',async (req,res)=>{
   let resData = await typeModel.find();
    res.send({
        msg:'请求成功',
        code:1,
        data:resData
    })
})

module.exports = router;